package com.flyan.game.motafx.core.util.cutscene;

import com.almasb.fxgl.cutscene.Cutscene;
import com.almasb.fxgl.dsl.FXGL;
import lombok.experimental.UtilityClass;

import java.util.List;

import static com.almasb.fxgl.dsl.FXGL.getAssetLoader;

/**
 * 过场动画实用工具
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/8
 */
@UtilityClass
public final class CutsceneUtils {

    /**
     * 开始一个过场动画
     *
     * @param scriptAssetName 脚本资源名称
     */
    public static void startCutscene(String scriptAssetName) {
        List<String> script = getAssetLoader().loadText(scriptAssetName);
        Cutscene cutScene = new Cutscene(script);
        FXGL.getCutsceneService().startCutscene(cutScene);
    }

    /**
     * 通过脚本开始一个过场动画
     *
     * @param script 脚本
     */
    public static void startCutsceneByScript(String script, Runnable onFinished) {
        String[] split = script.split("\n");
        Cutscene cutScene = new Cutscene(List.of(split));
        FXGL.getCutsceneService().startCutscene(cutScene, onFinished);
    }

}
